{config_load file=global.conf}
{config_load file="_form_calc.conf" section="`$lang`"}

{*
{if !$Staff->UserPairs()}
	{assign var="pairs" value="aaaaaaa"}
{else}
	{assign var="pairs" value=$Staff->UserPairs()}
{/if}

<br>


{foreach item="itr" from=$pairs}
	{foreach item="itr1" from=$itr}
		{$itr1}&nbsp;
	{/foreach}
{/foreach}

*}
<!--
<script type="text/javascript" language="JavaScript" src="{#scripts_dir#}/fValidate/fValidate.lang-enUS.js"></script>
<script type="text/javascript" language="JavaScript" src="{#scripts_dir#}/fValidate/fValidate.config.js" ></script>
<script type="text/javascript" language="JavaScript" src="{#scripts_dir#}/fValidate/fValidate.core.js" ></script>
<script type="text/javascript" language="JavaScript" src="{#scripts_dir#}/fValidate/fValidate.validators.js" ></script>
onSubmit="return validateForm( this, 0, 0, 0, 1, 16);"

-->
<script type="text/javascript" language="JavaScript" src="{#scripts_dir#}/globalFuncs.js" ></script>

<input type="hidden" id="currYear" value="{$calc->dDate.currYear}" />
<input type="hidden" id="currMonth" value="{$calc->dDate.currMonth}" />
<input type="hidden" id="startYear" value="{$calc->dDate.startYear}" />

<script type="text/javascript" language="JavaScript" src="{#scripts_dir#}/globalFuncs.js" ></script>
<script type="text/javascript" language="JavaScript" src="{#scripts_dir#}/tooltip.js" ></script>
<script type="text/javascript" language="JavaScript" src="{#scripts_dir#}/numberFormat.js" ></script>
<script type="text/javascript">
{literal}


/////////////// onload  ///////////////////////////////////////


var systemID={/literal}'{$Staff->getSystem()}'{literal}

function afterBodyLoaded(){

	onLoadFunc();
	xajax.loadingFunction = Func1;
   xajax.doneLoadingFunction = Func2;

   xajax_getCalcResult(xajax.getFormValues("frm_calc"), 1, systemID, true);

}

addLoadEvent(afterBodyLoaded);


//////////////////// xajax /////////////////////////////////////

	function submitCalcAllForm() {
	    xajax_getCalcResult(xajax.getFormValues("frm_calc"), 1, systemID, true);
	    return false;
	}

	function submitCalcPairForm(PairID) {
		var pair_ID = PairID;
	    xajax_getCalcResult(xajax.getFormValues("frm_calc"), pair_ID, systemID);
	    return false;
	}

 function Func1(){
 	document.getElementById('calcResult').style.display = 'none';
   	document.getElementById('loadMessage').style.display = 'block';
   }

   function Func2(){
   	document.getElementById('loadMessage').style.display = 'none';
   	document.getElementById('calcResult').style.display = 'block';
    {/literal}
   	if (document.getElementById('submitButton').value == "{#_form_calc__btnRecalculate#}{*Recalculate*}")
   		window.location="#results";
   	document.getElementById('submitButton').value = "{#_form_calc__btnCalculate#}{*Calculate*}";
    {literal}
   }

 //////////////// calculator ///////////////////////////////////

 var monthDataArr = new Array();
 var months = 12;
 var currMonth;
 var currYear;
 var countTrades = 1;

 var currSystem = document.getElementById('id_selectsystem_system').value;
 var system2compare = 4;
 var systemStartMonth = 10;
 var systemStartYear = 2007;

 function setMnames(){
	 //var mNames = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
     {/literal}
     var mNames = new Array('{#_form_calc__mnthJan#}{*Jan*}',
                            '{#_form_calc__mnthFeb#}{*Feb*}',
                            '{#_form_calc__mnthMar#}{*Mar*}',
                            '{#_form_calc__mnthApr#}{*Apr*}',
                            '{#_form_calc__mnthMay#}{*May*}',
                            '{#_form_calc__mnthJun#}{*Jun*}',
                            '{#_form_calc__mnthJul#}{*Jul*}',
                            '{#_form_calc__mnthAug#}{*Aug*}',
                            '{#_form_calc__mnthSep#}{*Sep*}',
                            '{#_form_calc__mnthOct#}{*Oct*}',
                            '{#_form_calc__mnthNov#}{*Nov*}',
                            '{#_form_calc__mnthDec#}{*Dec*}');
     {literal}
	 return mNames;
 }

 function getBalance(){
  	document.getElementById('balance').value = parseInt(document.getElementById('deposit').value * document.getElementById('credit').value);
  	document.getElementById('balanceText').innerHTML = FormatNumberBy3(document.getElementById('balance').value);
  	//if(document.getElementById('contract').value < document.getElementById('balance').value)
  		//document.getElementById('contract').value = document.getElementById('balance').value;
  		document.getElementById('contract').value = document.getElementById('lot').value * 100000;
  	return true;
 }

 function getCurrDate(){
 	var now = new Date();
  	currMonth = now.getMonth()+1;
  	currYear = now.getYear();
   currYear = 2007;
	//var monthday = now.getDate();
	return true;
 }

 function fillMonths(pointer){

 	var newOption;
 	var monthsPointer = 12;
 	var optionsHTML = '';
 	var mNames = setMnames();
 	var startMonth = 0;
 	var isCurrYear = (parseInt(document.getElementById('year_'+pointer).value)==document.getElementById('currYear').value);

	// if selected system and not current year
 	if (currSystem==system2compare && pointer=='from' && !isCurrYear) startMonth = systemStartMonth-1;

	//if current year do not show not passed month
    if (isCurrYear) monthsPointer = parseInt(document.getElementById('currMonth').value); //-2

    optionsHTML += '<select class="selectSmall" onClick="javascript:submitCaption();" name="month_'+pointer+'" id="month_'+pointer+'">';
 	for (var i=startMonth; i<monthsPointer; i++){
 		optionsHTML += '<option value="'+(i+1)+'">';
 		optionsHTML += mNames[i];
 		optionsHTML += '</option>';
 	}
 	optionsHTML += '</select>';
    //alert(monthsPointer);
    document.getElementById('m_'+pointer).innerHTML = optionsHTML;
  	return true;
 }

  function fillYears(pointer){

 	var optionsHTML = '';
 	var mNames = setMnames();
 	var startYear = document.getElementById('startYear').value
 	var currYear = document.getElementById('currYear').value

    if (currSystem == system2compare) startYear = systemStartYear;

    optionsHTML += '<select class="selectSmall" onClick="javascript:submitCaption();" onChange=javascript:fillMonths("'+pointer+'"); name="year_'+pointer+'" id="year_'+pointer+'">';
 	for (var i=startYear; i<=currYear; i++){
 		optionsHTML += '<option value="'+(i)+'">';
 		optionsHTML += i;
 		optionsHTML += '</option>';
 	}
 	optionsHTML += '</select>';
    //alert(optionsHTML)
    document.getElementById('y_'+pointer).innerHTML = optionsHTML;
  	return true;
 }


function validateForm(){

 	var y_f = document.getElementById('year_from').value;
 	var y_t = document.getElementById('year_to').value;
 	var m_f = document.getElementById('month_from').value;
 	var m_t = document.getElementById('month_to').value;

 	var balance = document.getElementById('balance').value;
 	var contract = document.getElementById('contract').value;
/*
 	var errorMsg1 = "'From' date can't be greater then 'To' date";
 	var errorMsg2 = "Contract Size can't be greater than your Balance";
 	var errorMsg3 = "Please fill all required fields correctly !";
*/
    {/literal}
 	var errorMsg1 = "{$smarty.config._form_calc__errorMsg1}{*'From' date can't be greater then 'To' date*}";
 	var errorMsg2 = "{$smarty.config._form_calc__errorMsg2}{*Contract Size can't be greater than your Balance*}";
 	var errorMsg3 = "{$smarty.config._form_calc__errorMsg3}{*Please fill all required fields correctly !*}";
    {literal}

 	var timeRangeArr = new Array();
 	var monthRange


 	if (y_f > y_t) {
 		alert(errorMsg1);
 		return false;
 	}
 	else if (m_f > parseInt(m_t) && y_f == y_t) {
 		alert(errorMsg1);

 		return false;
 	}
 	else if ((balance-contract)<0) {
 		alert(errorMsg2);
 		return false;
 	}
 	if (document.getElementById('deposit').value=="" || document.getElementById('deposit').value==" " || document.getElementById('deposit').value<=0) {
 		alert(errorMsg3);
 		return false;
 	}
 	else if (document.getElementById('contract').value=="" || document.getElementById('contract').value==" " || document.getElementById('contract').value<=0) {
 		alert(errorMsg3);
 		return false;
 	}

 	var ctr = 0;
 	var cbArr = new Array();
 	while(document.getElementById('pair'+ctr)){
 		cbArr.push(ctr);
 		ctr++;
 	}
 	//alert(cbArr);

  	return true;
 }



  function showTotalStats(){
 	document.getElementById('calcStats').style.display = "block"
  	return true;
 }


  function Calculate(vol,pair){
  	if (validateForm()) {
  		if (vol=='all') {
    		submitCalcAllForm();
    	} else {
            submitCalcPairForm(pair);
    	}
    }
 }


 function setDefYear(){
 	document.getElementById('year_from').value = document.getElementById('currYear').value-1;
 	document.getElementById('year_to').value = document.getElementById('currYear').value;
 }

  function setDefMonth(){
 	document.getElementById('month_to').value = parseInt(document.getElementById('currMonth').value); //-2
 }

 function onLoadFunc(){

 	getCurrDate();
 	getBalance();
  	fillYears('from');
  	fillYears('to');
  	setDefYear();
  	fillMonths('from');
  	fillMonths('to');
  	setDefMonth();
  	advSettings();
  	setProgramParams();
  }

 function advSettings(){
 	  var dispSettings;
 	  var ctr=1;

 	  if (document.getElementById('adv_set').style.display == "none"){
 	  	 dispSettings = "block";
         {/literal}
 	  	 document.getElementById('ASstate').innerHTML = "{#_form_calc__msgHideAdvSettings#}{*Hide Advanced Settings*} < ";
         {literal}
 	  } else {
 	  	dispSettings = "none";
        {/literal}
 	  	document.getElementById('ASstate').innerHTML = "{#_form_calc__msgShowAdvSettings#}{*Show Advanced Settings*} > ";
        {literal}
 	  }

      document.getElementById('adv_set').style.display = dispSettings;
      for (ctr; ctr<13; ctr++){
      	if(document.getElementById('spread_cell'+ctr)) document.getElementById('spread_cell'+ctr).style.display = dispSettings;
 	}
 }

  function submitCaption(){
    {/literal}
 	 document.getElementById('submitButton').value = "{#_form_calc__btnRecalculate#}{*Recalculate*}";
     {literal}
 }

   function pairClick(pairCB){
 	 document.getElementById(pairCB).checked = !document.getElementById(pairCB).checked;
 }

 function setProgramParams(){
 	 document.getElementById('deposit').value = document.getElementById('calcDeposit').value;
 	 document.getElementById('lot').value = document.getElementById('calcLot').value;
 	 document.getElementById('credit').value = document.getElementById('calcLeverage').value;
 }

/*
var tooltip_slip = '<b>Slippage:</b> execution of order for a price different than expected (ordered).<br>Main reasons for slippage are - "fast" market, low liquidity and low broker&#39;s<br>ability to execute orders.';
var tooltip_dd = '<b>Maximum Drawdown:</b> the magnitude of a decline in account value, either in percentage or dollar terms, as measured from peak to subsequent trough.  For example, if a trader&#39;s account increased in value from $10,000 to $20,000, then dropped to $15,000, then increased again to $25,000, that trader would have had a maximum drawdown of $5,000 (incurred when the account declined from $20,000 to $15,000) even though that trader&#39;s account was never in a loss position from inception. <br><br>In other words, if you were to enter in on the day the equity curve made a peak, how much would you have lost if you bailed out at the lowest point.';
var tooltip_margin = '<b>Margin Ratio:</b> margin trading allows FX market participants to trade much larger amounts than they have deposited. For example, with a margin ratio of 20:1 and a deposit of $10,000, an investor can trade amounts up to $200,000. Trading in larger volumes, in turn, allows these investors to take better advantage of small price movements.';
*/

{/literal}
var tooltip_slip = '{$smarty.config._form_calc__tooltipSlip|escape:"quotes"}{*<b>Slippage:</b> execution of order for a price different than expected (ordered).<br>Main reasons for slippage are - "fast" market, low liquidity and low broker&#39;s<br>ability to execute orders.*}';
var tooltip_dd = '{$smarty.config._form_calc__tooltipDD|escape:"quotes"}{*<b>Maximum Drawdown:</b> the magnitude of a decline in account value, either in percentage or dollar terms, as measured from peak to subsequent trough.  For example, if a trader&#39;s account increased in value from $10,000 to $20,000, then dropped to $15,000, then increased again to $25,000, that trader would have had a maximum drawdown of $5,000 (incurred when the account declined from $20,000 to $15,000) even though that trader&#39;s account was never in a loss position from inception. <br><br>In other words, if you were to enter in on the day the equity curve made a peak, how much would you have lost if you bailed out at the lowest point.*}';
var tooltip_margin = '{$smarty.config._form_calc__tooltipMargin|escape:"quotes"}{*<b>Margin Ratio:</b> margin trading allows FX market participants to trade much larger amounts than they have deposited. For example, with a margin ratio of 20:1 and a deposit of $10,000, an investor can trade amounts up to $200,000. Trading in larger volumes, in turn, allows these investors to take better advantage of small price movements.*}';
var tooltip_spread = '{$smarty.config._form_calc__tooltipSpread|escape:"quotes"}{*<b>Spread:</b> difference between the bid and ask price of a currency.*}';




{literal}




{/literal}
</script>


<link href="{#styles_dir#}/form.css" rel="stylesheet" type="text/css">

    <ul id="errors"></ul>

<table border="0" class="form" cellpadding="0"><tr><td>
<form method="post" enctype="multipart/form-data" id="frm_calc" name="frm_calc" action="javascript:void(null);" >

<table border="0" width="550" cellpadding="3">

    <tr><td width="130">
    	<label for="data_deposit"><nobr>{#_form_calc__labelDeposit#}{*Initial Deposit:*} </nobr></label></td><td>
        <input onChange="javascript:getBalance(); submitCaption();" class="input" onChange="javascript:getBalance();" type="text" id="deposit" name="data_deposit" value="10000" alt="blank"  emsg="Deposit can not be blank."> {#_form_calc__labelUSD#}{*USD*}
    </td></tr>
    <tr ><td>

    	<label for="data_credit"><nobr>{#_form_calc__labelLeverage#}{*Margin Ratio (Leverage):*} </nobr></label></td><td>
        <select onChange="javascript:getBalance(); submitCaption();" id="credit" class="select" name="data_credit">
        <option value="1">1:1</option>
        <option value="2">2:1</option>
        <option value="3">3:1</option>
        <option value="5">5:1</option>
        <option value="10">10:1</option>
        <option value="20">20:1</option>
        <option value="50">50:1</option>
        <option value="100" selected>100:1</option>
        <option value="200">200:1</option>
        </select>
        <span class="tip" onmouseover="tooltip(tooltip_margin);" onmouseout="exit();"><img src="{#images_dir#}/hint_bulb.gif" /></span>
    </td></tr>

    <tr ><td width="130" id="contract_row1">
    		<label for="data_contract"><nobr>{#_form_calc__labelContract#}{*Contract Size:*} </nobr></label>
    		</td><td id="contract_row2">
    		<select onChange="javascript:getBalance(); submitCaption();" id="lot" class="select" name="data_lot">
        <option value="0.1">0,1</option>
        <option value="0.2">0,2</option>
        <option value="0.5" selected>0,5</option>
		<option value="0.7">0,7</option>
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="5">5</option>
        <option value="10">10</option>
		<option value="20">20</option>
		<option value="30">30</option>
        </select> {#_form_calc__labelLot#}
        	<input onChange="javascript:submitCaption();" class="input" type="hidden" id="contract" name="data_contract" value="100000" />
    		</td></tr>

    <tr style="display: none"><td>
    <label for="data_balance"><nobr>{#_form_calc__labelBalance#}{*Balance:*} </nobr></label></td><td>
        <span id="balanceText"></span><input onChange="javascript:submitCaption();" type="hidden" id="balance" name="data_balance" >
    </td></tr>
    <tr ><td>

    <label><label for="data_range"><nobr>{#_form_calc__labelRange#}{*Time Range:*} </nobr></label>
    <br><img width="130" height="1" src="{#images_dir#}/spacer.gif" /></td><td><nobr>
        {#_form_calc__labelFromYear#}{*From Y*}
        <span id="y_from"></span>
        &nbsp;{#_form_calc__labelFromMonth#}{*M*}&nbsp;
        <span id="m_from"></span>
        &nbsp;&nbsp;
         {#_form_calc__labelToYear#}{*To Y*}
         <span id="y_to"></span>
         &nbsp;{#_form_calc__labelToMonth#}{*M*}&nbsp;
        <span id="m_to"></span>&nbsp;</nobr>
    </td></tr>


    <tr style="display: none"><td valign="top"><nobr>{#_form_calc__labelPairs#}{*Currency pairs:*} </nobr></td>
    <td>
    	<table border="0"><tr>
    	{assign var="firstSpread" value="1"}
        {section start=0 step=1 name=pair loop=$pairs}
        	{section name=item loop=$sysTrades}
	           {if $sysTrades[item]==$calc->pairsArr[pair].TradeID}

		        	<td width="85"><nobr>
		            <input type="checkbox" onClick="javascript:submitCaption();" id="pair{$smarty.section.pair.iteration}"
                      checked
				    {foreach item="UserPair" from=$UserPairs}
		        	 	{*if $UserPair.TradeID==$calc->pairsArr[pair].TradeID || $pairs_num==0} {/if*}
					{/foreach}
					{*if $pairs_num==0} {/if*}
		        	 {*if $calc->pairsArr[pair].TradeID==2400103 || $calc->pairsArr[pair].TradeID==2400503} {/if*}

		        	 value="{$calc->pairsArr[pair].TradeID}" name="data_trades[]">
		                <a href="javascript:void(null);" onclick="javascript:pairClick('pair{$smarty.section.pair.iteration}');">{$calc->pairsArr[pair].Pair}</a>&nbsp;</td>
		                <td id="spread_cell{$smarty.section.pair.iteration}"><nobr>{#_form_calc__labelSpread#}&nbsp;
		                <select onClick="javascript:submitCaption();" id="spread{$smarty.section.pairs.iteration+1}" name="{$calc->pairsArr[pair].TradeID}">
		                {section start=0 step=1 name=s1 loop=$spreads}
					        <option
					        {if $calc->pairsArr[pair].defSpread==$spreads[s1]} selected {/if}
					         value="{$spreads[s1]}">{$spreads[s1]}</option>
					     {/section}
					     </select>

						{* show Spread tooltip only after second pair *}
					     {if $firstSpread=="2"}
					     	<span class="tip" onmouseover="tooltip(tooltip_spread);" onmouseout="exit();"><img src="{#images_dir#}/hint_bulb.gif" />
					     	</span>
					     	{assign var="firstSpread" value=$firstSpread+1}
					     {else}
					     	{assign var="firstSpread" value=$firstSpread+1}
					     	<img src="{#images_dir#}/spacer.gif" width="16" height="16" />
					     {/if}

					     </nobr>
					  </td>
					  <script type="text/javascript">
		                if(countTrades%2==0) document.write("</tr><tr>");
		                countTrades++;
					  </script>

			  	{/if}
			  {/section}
        	{/section}
        </tr></table>
    </td></tr>
    <tr style="display: none"><td>{#_form_calc__labelDetalisation#}{*Detalisation*}</td><td>
        <input type="radio" name="detalisation" value="M">{#_form_calc__labelDetalMonth#}{*Monthly*}&nbsp;&nbsp;&nbsp;
        <input type="radio" name="detalisation" value="W">{#_form_calc__labelDetalWeek#}{*Weekly*}&nbsp;&nbsp;&nbsp;
        <input checked type="radio" name="detalisation" value="D">{#_form_calc__labelDetalDay#}{*All*}
    </td></tr>
    <tr style="display: none">
    <td><label><label for="data_reinvest"><nobr>{#_form_calc__labelReinvest#}{*Time Range:*} Reinvest</nobr></label>
    <br><img width="130" height="1" src="{#images_dir#}/spacer.gif" /></td><td>
    <input type="checkbox" name="data_reinvest" checked="checked">
    </td></tr>
    </table>

    	<table  border="0" id="adv_set">
        <tr><td id="slippage_row1"  width="190">
    		{#_form_calc__labelSlippage#}{*Slippage:*}
    		<br><img width="190" height="1" src="{#images_dir#}/spacer.gif" /></td>
    		<td id="slippage_row2"><select id="slippage" name="data_slippage">
			        <option value="0">0 {#_form_calc__labelPips#}{*pips*}</option>
			        <option value="1">1 {#_form_calc__labelPips#}{*pips*}</option>
			        <option value="2">2 {#_form_calc__labelPips#}{*pips*}</option>
			        <option value="3">3 {#_form_calc__labelPips#}{*pips*}</option>
			        <option value="4">4 {#_form_calc__labelPips#}{*pips*}</option>
			        <option value="5">5 {#_form_calc__labelPips#}{*pips*}</option>
			     </select>
	<span class="tip" onmouseover="tooltip(tooltip_slip);" onmouseout="exit();"><img src="{#images_dir#}/hint_bulb.gif" /></span>

    	</td></tr>
    </table>
    </td></tr>
    <tr style="display: none"><td>&nbsp;<a onClick="javascript:advSettings();" href="javascript:void(null);" class="bm"><span id="ASstate"></span></a></td>
    <td>&nbsp;</td></tr>
	<tr style="display: none">
	<td colspan="2"><span style="font-size:11px;">{#_form_calc__msgRisk#}&nbsp;{* * Without proper risk management, this high degree of leverage can lead to large losses as well as gains.*}</span></td></tr>
    </table>
    <table border="0" cellpadding="0">
    	<tr><td width="180">
    	<br><input type="submit" class="button" value="{#_form_calc__btnCalculate#}{*Calculate*}" id="submitButton" onClick="Calculate('all',false);">

    	</td></tr>
    </table>
</form>



<div id="loadMessage" style="font-size: 12pt; display: none;">
            <h2><img src="{#images_dir#}/loading.gif">&nbsp;{#_form_calc__msgCalculate#}{*Calculating...*}</h2><br><br>
</div>
<a name="results"></a>
<div id="calcResult"></div>
<div id="calcAjax"></div>

    <br>
